
//
//  FristVC.swift
//  SwiftUITemp
//
//  Created by MyMac on 15/10/13.
//  Copyright (c) 2015年 tongfang. All rights reserved.
//

import UIKit
import Foundation
//定义一个协议
 protocol transmitValue :NSObjectProtocol {

    func valueChange (_ value:String)
  // optional static func classFunc ()
     var proprtoy :Int {get set}
    //静态属性
  static var classP :Int {get set}
}



class FristVC: UIViewController {
    var delegate :transmitValue?
    //swift中声明一个变量／常亮 就必须给他赋值,除非是可选值
    var closure : (_ str:String) -> String={ (str : String) ->String in
        return str
        }
    
    
    override func viewDidLoad() {
        super.viewDidLoad()

        self.view.backgroundColor=UIColor.green
        
        let tempBtn : UIButton = UIButton(frame: CGRect(x: 0, y: 200, width: 320, height: 44))
        tempBtn.setTitle("闭包传值", for:UIControlState())
        tempBtn.backgroundColor=UIColor.red
        tempBtn.addTarget(self, action: #selector(FristVC.closureClick(_:)), for: UIControlEvents.touchUpInside)
        
        self.view.addSubview(tempBtn)
        
        
        
    }
    
  override  func touchesBegan(_ touches: Set<NSObject>, with event: UIEvent) {
   
    if (delegate != nil || delegate?.responds(to: Selector(("valueChange"))) != nil) {
    
     delegate?.valueChange("代理传值")
        }
    
    }
    func closureClick (_ btn:UIButton){
    
   _ = closure ("我是闭包")
    let vc=OCViewController()
        vc .addTitle("OC")
        self.navigationController?.pushViewController(vc, animated: true)
    
    
    }
    
}
